import Dialog from ".";
import { observer } from "mobx-react";
import { Row, Col, Radio } from 'antd';
import { WeaFormItem, WeaInput, WeaSelect, WeaCheckbox, WeaBrowser, WeaTab, WeaLocaleProvider, WeaInputNumber, WeaError, WeaHelpfulTip } from 'ecCom';
import OperatorSet from "../path-template/OpreatorSet";
const getLabel = WeaLocaleProvider.getLabel;

import './NodeModal.less';
@observer
export default class NodeModal extends React.Component {
    render() {
        const { store } = this.props;
        const { form } = store;
        const uuid = form.$('uuid').values();
        const nameField = form.$('name');
        const nodetype = form.$("nodeType");
        const operatortype = form.$('operatorType');
        const tablename = form.$('tablename');
        const tablekey = form.$('tablekey');
        const showfield = form.$('showfield');
        const hrmField = form.$('hrmField');
        const sqlWhere = form.$('sqlWhere');
        const isrecursion = form.$('isrecursion');
        const tablesup = form.$('tablesup');
        const relationtype = form.$('relationtype');
        const hrmresource = form.$('hrmresource');
        const hrmdepartment = form.$('hrmdepartment');
        const hrmsubcompany = form.$('hrmsubcompany');
        const rootids = form.$('rootids');
        const supnodefield = form.$('supnodefield');
        const nodefield = form.$('nodefield');
        const nodetypeOptions = [];
        if (uuid === "root") {
            nodetypeOptions.push({
                key: '0',
                title: getLabel('502714', '静态节点'),
            });

        } else if (store.parentNodeType && store.parentNodeType === '1') {
            nodetypeOptions.push({
                key: '1',
                title: getLabel('502715', '动态节点'),
            });
        } else {
            nodetypeOptions.push({
                key: '0',
                title: getLabel('502714', '静态节点'),
            });
            nodetypeOptions.push({
                key: '1',
                title: getLabel('502715', '动态节点'),
            });
        }
        const nodeTypeValue = nodetype.values();
        const operatorTypeValue = operatortype.values();
        const isDynamic = nodeTypeValue === "1";
        const isStatic = nodeTypeValue === "0";
        const isRecursion = isrecursion.values() == '1';
        const isDynamicCustom = isDynamic && operatorTypeValue === '3';
        const isResource = operatorTypeValue === '0';
        const isDept = operatorTypeValue === '1';
        const isSubCom = operatorTypeValue === '2';
        const isDynamicCustomRecursion = isDynamicCustom && isRecursion;
        const relationtypeValue = relationtype.values();
        const isPointNode = relationtypeValue === '0';
        const isRelateNode = relationtypeValue === '1';
        const isRoot = uuid === "root" ? true : false;
        const relationtypeOptions = [];
        if (store.parentNodeType && store.parentNodeType === '0') {
            relationtypeOptions.push({
                key: '0',
                showname: getLabel('502725', '指定节点'),
            });
        } else {
            relationtypeOptions.push({
                key: '1',
                showname: getLabel('502726', '关联上级节点'),
            });
        }
        const operateTypeOptions = [];
        if(store.parentOperateType){
            if (store.parentOperateType === '0') {
                operateTypeOptions.push({
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            } else if (store.parentOperateType === '1') {
                operateTypeOptions.push({
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                        key: '1',
                        showname: getLabel(502298, '部门'),
                    }, {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            } else if (store.parentOperateType === '2') {
                operateTypeOptions.push({
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                        key: '1',
                        showname: getLabel(502298, '部门'),
                    }, {
                        key: '2',
                        showname: getLabel(502299, '分部'),
                    }, {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            } else if (store.parentOperateType === '3') {
                operateTypeOptions.push(
                    {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            }
        }else{
                operateTypeOptions.push(
                {
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                    key: '1',
                    showname: getLabel(502298, '部门'),
                }, {
                    key: '2',
                    showname: getLabel(502299, '分部'),
                }, {
                    key: '3',
                    showname: getLabel(502465, '自定义'),
                });
        }
        const parentTableName = store.parentTableName;
        const getLabelString = new Map([
            ['数据显示条件', getLabel('528032','数据显示条件')],
            ['格式', getLabel('528038','格式') ],
            ['动态参数说明', getLabel('528039','动态参数说明：')],
            ['输入{userid}',getLabel('528040','1.输入{userid}表示当前用户id')],
            ['输入{subcompanyid}',  getLabel('528041','2.输入{subcompanyid}表示用户的分部id') ],
            ['输入{departmentid}', getLabel('528042','3.输入{departmentid}表示用户的部门id')],
            ['输入{workcode}', getLabel('528043','4.输入{workcode}表示用户的工作编号') ],
            ['输入{date}', getLabel('528044','5.输入{date}表示当前日期')],
        ]);
        return (
            <Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@1qg3y6`}
                dialog={store}
                className="edc-path-node-modal"
            >
                <div className="edc-path-node-form">
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@2533ya`} className="edc-addNode-item-row">
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@akakus`} span={24}>
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@etawwy`}
                                label={getLabel('502717', '节点名称')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 10 }}
                                error={form.getError({ domkey: ['name'] })}
                            >
                                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@jwablx`} style={{ marginLeft: 10 }}
                                    tipPosition='bottom'
                                    ref={ref => store.nodeNameErr = ref}
                                    error={getLabel('512075','节点名称为空')}>
                                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@pca9tu`} style={{ width: 280 }} viewAttr={3} {...nameField.bind()} />
                                </WeaError>
                            </WeaFormItem>
                        </Col>
                    </Row>
                    <div className="edc-node-setting">
                        <div style={{ marginBottom: 5 }}>
                            <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@jqlqe6`}
                                {...nodetype.bind()}
                                datas={nodetypeOptions}
                                keyParam="key"
                                selectedKey={nodeTypeValue}
                                onChange={store.changeNodeType}
                            ></WeaTab>
                        </div>
                        {isDynamic && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@mkquog`} className="edc-addNode-item-row">
                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@n07nc2`} span={24}>
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@xl0r8y`}
                                    label={getLabel('502718', '解析类型')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}

                                >
                                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@j3d8ak`}
                                        className="edc-addNode-set-select"
                                        viewAttr={3}
                                        detailtype={3}
                                        options={operateTypeOptions}
                                        {...operatortype.bind()}
                                        onChange={store.changeOperatorType}
                                    />
                                </WeaFormItem>
                            </Col>
                        </Row>}
                        {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@squpeu`} className="edc-addNode-item-row">
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@044x6y`}
                                label={getLabel('502719', '自定义对象表名')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 10 }}
                                error={form.getError({ domkey: ['tablename'] })}
                            >
                                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@x343bq`}
                                    tipPosition='bottom'
                                    ref={ref => store.tableNameErr = ref}
                                    error={getLabel('512076','自定义对象表名为空')}>
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@yf45es`} 
                                        inputStyle={{ width: 265 }}
                                        viewAttr={3} 
                                        {...tablename.bind()} 
                                        type={'EdcLocalTables'} 
                                        title={getLabel('512077','选择表或视图')}
                                        hasAdvanceSerach= {true}
                                     />
                                </WeaError>
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@7em3nj`} className="edc-addNode-item-row">
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@x1fxrx`}
                                label={getLabel('502720', '自定义对象主键')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 10 }}
                                error={form.getError({ domkey: ['tablekey'] })}
                            >
                                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@eoc2bg`}
                                    tipPosition='bottom'
                                    ref={ref => store.tableKeyErr = ref}
                                    error={getLabel('512078','自定义对象主键为空')}>
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@1pqril`} 
                                        inputStyle={{ width: 265 }} 
                                        viewAttr={3} 
                                        {...tablekey.bind()} 
                                        type={'EdcTableFields'} 
                                        title={getLabel('512079','选择字段')}
                                        hasAdvanceSerach= {true}
                                        completeParams={{tableName:tablename.values()}}
                                        dataParams={{tableName:tablename.values()}}
                                    />
                                </WeaError>
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@4g47y5`} className="edc-addNode-item-row">
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@cqh10j`}
                                label={getLabel('502721', '自定义对象显示名称')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 10 }}
                                error={form.getError({ domkey: ['showfield'] })}
                            >
                                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@mmw2fl`}
                                    tipPosition='bottom'
                                    ref={ref => store.showFieldErr = ref}
                                    error={getLabel('512090','自定义对象显示名称为空')}>
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@bpmehf`} 
                                        inputStyle={{ width: 265 }} 
                                        viewAttr={3} 
                                        {...showfield.bind()} 
                                        type={'EdcTableFields'} 
                                        title={getLabel('512079','选择字段')}
                                        hasAdvanceSerach= {true}
                                        completeParams={{tableName:tablename.values()}}
                                        dataParams={{tableName:tablename.values()}}
                                    />
                                </WeaError>
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@7g66ov`} className="edc-addNode-item-row">
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@ogomuz`}
                                label={getLabel('512091','人力资源字段名')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 10 }}
                                error={form.getError({ domkey: ['hrmField'] })}
                            >
                                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@lxz6xi`}
                                    tipPosition='bottom'
                                    ref={ref => store.hrmFieldErr = ref}
                                    error={getLabel('512092','人力资源字段名为空')}>
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@ncp2bs`} 
                                        inputStyle={{ width: 265 }} 
                                        viewAttr={3} 
                                        {...hrmField.bind()} 
                                        type={'EdcTableFields'} 
                                        title={getLabel('512079','选择字段')}
                                        hasAdvanceSerach= {true}
                                        completeParams={{tableName:tablename.values()}}
                                        dataParams={{tableName:tablename.values()}}
                                    />
                                </WeaError>
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@7ffvgo`} className="edc-addNode-item-row">
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@brox20`}
                                label={getLabel('502722', '是否递归解析')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['isrecursion'] })}
                            >
                                <WeaCheckbox ecId={`${this && this.props && this.props.ecId || ''}_WeaCheckbox@9pgeex`}
                                    helpfulTip={getLabel('502722', '是否递归解析')}
                                    display="switch"
                                    style={{ display: 'inline' }}
                                    {...isrecursion.bind()}
                                />
                            </WeaFormItem>
                        </Row>}
                        {/*  && */}
                        {isDynamicCustomRecursion &&  <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@njku9o`} className="edc-addNode-item-row">
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@0487ll`}
                                label={getLabel('502723', '上级字段')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 10 }}
                                error={form.getError({ domkey: ['tablesup'] })}
                            >
                                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@6x5c7r`}
                                    tipPosition='bottom'
                                    ref={ref => store.tableSupErr = ref}
                                    error={getLabel('512093','上级字段为空')}>
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@5kl2en`} 
                                        inputStyle={{ width: 265 }} 
                                        viewAttr={3} 
                                        {...tablesup.bind()} 
                                        type={'EdcTableFields'} 
                                        title={getLabel('512079','选择字段')}
                                        hasAdvanceSerach= {true}
                                        completeParams={{tableName:tablename.values()}}
                                        dataParams={{tableName:tablename.values()}}
                                    />
                                </WeaError>
                            </WeaFormItem>
                        </Row>}
                        {isDynamic && isPointNode && isResource &&
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@nlvnfi`} className="edc-addNode-item-row">
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@02c6pv`}
                                    label={getLabel('502727', '指定对象')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    error={form.getError({ domkey: ['hrmresource'] })}
                                >
                                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@ke9dn9`} tipPosition='bottom'
                                        ref={ref => store.objBrowserErr = ref}
                                        error={getLabel('512094','指定对象为空')}>
                                        <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@mwqoih`} inputStyle={{ width: 275 }} viewAttr={3} {...hrmresource.bind()} isSingle={false} type={17} title={getLabel('505966', '选择人员')} />
                                    </WeaError>
                                </WeaFormItem>
                            </Row>
                        }
                        {isDynamic && isPointNode && isDept &&
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@svjylg`} className="edc-addNode-item-row">
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@jb1uux`}
                                    label={getLabel('502727', '指定对象')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    error={form.getError({ domkey: ['hrmdepartment'] })}
                                >
                                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@202dpj`} tipPosition='bottom'
                                        ref={ref => store.objBrowserErr = ref}
                                        error={getLabel('512094','指定对象为空')}>
                                        <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@oauv4z`} inputStyle={{ width: 275 }} viewAttr={3} {...hrmdepartment.bind()} isSingle={false} type={57} title={getLabel('505972', '选择部门')} />
                                    </WeaError>
                                </WeaFormItem>
                            </Row>
                        }
                        {isDynamic && isPointNode && isSubCom &&
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@f9229z`} className="edc-addNode-item-row">
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@h9wn3k`}
                                    label={getLabel('502727', '指定对象')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    error={form.getError({ domkey: ['hrmsubcompany'] })}
                                >
                                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@g3ym2l`} tipPosition='bottom'
                                        ref={ref => store.objBrowserErr = ref}
                                        error={getLabel('512094','指定对象为空')}>
                                        <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@ho6x8q`} inputStyle={{ width: 275 }} viewAttr={3} {...hrmsubcompany.bind()} isSingle={false} type={194} title={getLabel('505970', '选择分部')} />
                                    </WeaError>
                                </WeaFormItem>
                            </Row>
                        }
                        {isPointNode && isDynamicCustom &&
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@fxd7sf`} className="edc-addNode-item-row">
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@761ljg`}
                                    label={getLabel('512095','指定主键')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 10 }}
                                    error={form.getError({ domkey: ['rootids'] })}
                                >
                                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@f8ejsm`}
                                        tipPosition='bottom'
                                        ref={ref => store.rootIdErr = ref}
                                        >
                                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@o543ih`} style={{ width: 265 }} viewAttr={2} {...rootids.bind()} />
                                    </WeaError>

                                </WeaFormItem>
                            </Row>
                        }
                        {isPointNode && isDynamicCustom &&<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@kiq61v`} className="edc-addNode-item-row">
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@fa0vai`}
                                    label={getLabelString.get('数据显示条件') }
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 10 }}
                                >
                                    <div style={{display:'flex'}}>
                                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@isjcg9`} 
                                        style={{ width: 265 }} viewAttr={2} {...sqlWhere.bind()}
                                         />
                                         <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@zuv1hw`} style={{ padding: '5px 0px 0px 5px' }}
                                            title={
                                                <div>
                                                    <p>{`${getLabelString.get('格式')}：a='1' and b='2' and c='{userid}'`}</p>
                                                    <p>{getLabelString.get('动态参数说明') }</p>
                                                    <p>{getLabelString.get('输入{userid}') }</p>
                                                    <p>{getLabelString.get('输入{subcompanyid}') }</p>
                                                    <p>{getLabelString.get('输入{departmentid}') }</p>
                                                    <p>{getLabelString.get('输入{workcode}') }</p>
                                                    <p>{getLabelString.get('输入{date}') }</p>
                                                </div>
                                            }
                                    placement="bottom" />
                                    </div>
                                </WeaFormItem>
                            </Row>}
                        {isDynamicCustom && isRelateNode &&
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@e5ur32`} className="edc-addNode-item-row">
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@r4r5f8`}
                                    label={getLabel('502729', '上级节点字段')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 8 }}
                                    error={form.getError({ domkey: ['supnodefield'] })}
                                >
                                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@bu340y`}
                                        tipPosition='bottom'
                                        ref={ref => store.supnodefieldErr = ref}
                                        error={getLabel('512096','上级节点字段为空')}>
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@2v5ihc`} 
                                        inputStyle={{ width: 265 }} 
                                        viewAttr={parentTableName?3:1} 
                                        {...supnodefield.bind()} 
                                        type={'EdcTableFields'} 
                                        title={getLabel('512079','选择字段')}
                                        hasAdvanceSerach= {true}
                                        completeParams={{tableName:parentTableName}}
                                        dataParams={{tableName:parentTableName}}
                                    />
                                    </WeaError>
                                </WeaFormItem>
                            </Row>
                        }
                        {isDynamicCustom && isRelateNode &&
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@fjd1jo`} className="edc-addNode-item-row">
                                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@oli8uj`}
                                    label={getLabel('502730', '本级节点字段')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 8 }}
                                    error={form.getError({ domkey: ['nodefield'] })}
                                >
                                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@0lb6px`}
                                        tipPosition='bottom'
                                        ref={ref => store.nodefieldErr = ref}
                                        error={getLabel('512098','本级节点字段为空')}>
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@x8zgse`} 
                                        inputStyle={{ width: 265 }} 
                                        viewAttr={3} 
                                        {...nodefield.bind()} 
                                        type={'EdcTableFields'} 
                                        title={getLabel('512079','选择字段')}
                                        hasAdvanceSerach= {true}
                                        completeParams={{tableName:tablename.values()}}
                                        dataParams={{tableName:tablename.values()}}
                                    />
                                    </WeaError>
                                </WeaFormItem>
                            </Row>
                        }
                    </div>
                    {(isDynamic || isStatic) && <OperatorSet ecId={`${this && this.props && this.props.ecId || ''}_OperatorSet@fjx1d7`} store={store} />}
                </div>
            </Dialog>
        )
    }
}